/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

   

    var map;
    var gdir;
    var geocoder ;
    var address;

   /* function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));                 //Initialise une carte google Map dans le div map_canevas
        gdir = new GDirections(map, document.getElementById("direction"));     //Initialise le div direction pour afficher la direction à prendre
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        //setDirections("Paris", "Franconville", "fr");
      }
    }

    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,                   //Initialise un itinéraire
                { "locale": locale });
    }*/


    function initialize() {
      map = new GMap2(document.getElementById("carte"));
      map.setCenter(new GLatLng(48.98404743872055, 2.226276397705078), 15);
      map.addControl(new GLargeMapControl);
      GEvent.addListener(map, "click", getAddress);
      geocoder = new GClientGeocoder();
    }

    function getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }

    function showAddress(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Status Code:" + response.Status.code);
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);

        document.getElementById("pays").value =place.address;


        marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' +
        '<b>latlng:</b>' + place.Point.coordinates[0] + "," + place.Point.coordinates[1] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
      }
    }

    function trouverLocalisation(rue,ville,code)
    {
        var depart=rue+", "+ville+", "+code;

        //document.write(depart);

        geocoder.getLocations(depart,afficherLocalisation);
    }
    
    function afficherLocalisation(point)
    {
        //document.write(point.lat());
        var gpoint = new GPoint(point.lat(),point.lng());  // Création du point correspondant aux coordonnées nous intéressant
        var marker = new GMarker(gpoint);  // Création d'un marqueur localisé sur ce point
        map.addOverlay(marker);
    }




    